<?php
session_start();
include_once("./c/config.php");
$access_token = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appId.'&secret='.$secret.'&code='.$_GET['code'].'&grant_type=authorization_code';
$access = file_get_contents($access_token);
$accessObj = json_decode($access);
$openid   = $accessObj->openid;

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
$query=$mysqli->query("select openid from users where openid='".$openid."'  limit 0, 1");
$_SESSION['openid']=$openid;
if($query->num_rows>0){
}else{
	if (isset($openid) && !empty($openid)){
		$sql = "insert into users(openid,createtime) values ('".$openid."','".date("Y-m-d H:i:s")."' )";
		$mysqli->query($sql);
	}
}
header('Location: game.php');
exit;